package com.han.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Author: Hanjiafeng
 * @Date: 2020/6/28
 * @Desc:
 */
public class Encryptors {
    public static String md5(String raw) {

        byte[] secretBytes;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(raw.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("No Such md5 Algorithm！");
        }
        StringBuilder md5code = new StringBuilder(new BigInteger(1, secretBytes).toString(16));
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code.insert(0, "0");
        }
        return md5code.toString();
    }
}
